local skill = fk.CreateSkill {
  name = "#lvs__war_elephant_skill",
  tags = { Skill.Compulsory },
  attached_equip = "lvs__war_elephant",
}

skill:addEffect("distance", {
  correct_func = function(self, from, to)
    if to:hasSkill(skill.name) then
      return 2
    end
  end,
})

skill:addEffect(fk.AfterCardsMove, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player.dead then return end
    for _, move in ipairs(data) do
      if move.to == player and move.toArea == Card.PlayerEquip then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId).name == skill.attached_equip or Fk:getCardById(info.cardId).sub_type == Card.SubtypeOffensiveRide then
            return Fk.skills[skill.name]:isEffectable(player)
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local ids = {}
    for _, move in ipairs(data) do
      if move.to == player and move.toArea == Card.PlayerEquip then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId).name == skill.attached_equip then
            ids = table.filter(player:getCardIds("e"), function (id)
              return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide
            end)
          elseif Fk:getCardById(info.cardId).sub_type == Card.SubtypeOffensiveRide then
            ids = table.filter(player:getCardIds("e"), function (id)
              return Fk:getCardById(id).name == skill.attached_equip
            end)
          end
        end
      end
    end
    if #ids > 0 then
      player.room:moveCardTo(ids, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, skill.name, nil, true, player.id)
    end
  end,
})

return skill